define([], function() {
    'use strict';
    
    let threadsQueue = function (){
        this.queue = [];
        this.isExecute = false;
    }

    threadsQueue.prototype.add = function (func) {
        this.queue.push(func);
        if(!this.isExecute && typeof this.queue[0] === 'function') {
            this.isExecute = true;
            this.queue[0]();
        }
    }


    threadsQueue.prototype.execute = function () {
        this.popFirst();
        if(this.queue[0]) {
            this.queue[0]();
        }else{
            this.isExecute = false;
        }
    }


    threadsQueue.prototype.popFirst = function () {
        this.queue.splice(0, 1);
    }


    threadsQueue.prototype.getQueueLength = function () {
        return this.queue.length;
    }

    return new threadsQueue();
});